/*
 * FilledRect.cpp
 *
 *  Created on: Jul 6, 2009
 *      Author: kurt
 */

#include "FilledRect.h"
#include "DrawingCanvas.h"
#include "Types.h"
#include <pspgu.h>
#include <pspgum.h>
#include <sstream>
using namespace std;
using namespace objdraw;

FilledRect::~FilledRect() 
{
	
}
FilledRect::FilledRect() 
{
	start = Location(0,0);
	end = Location(0,0);
	color = Color(0,0,0);
	hidden = false;
	canvas = NULL;
}
FilledRect::FilledRect(const FilledRect & r)
{
	start = r.start;
	end = r.end;
	color = r.color;
	hidden = r.hidden;
	canvas = r.canvas;
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
FilledRect::FilledRect(float x, float y, float width, float height, DrawingCanvas * c)
{
	start = Location(x,y);
	end = Location(x+width, y+height);
	color = Color(0,0,0);
	hidden = false;
	canvas = c;
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
FilledRect::FilledRect(Location origin, float width, float height, DrawingCanvas * c)
{
	start = origin;
	end = Location(origin.x+width, origin.y+height);
	color = Color(0,0,0);
	hidden = false;
	canvas = c;
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
FilledRect::FilledRect(Location p0, Location p1, DrawingCanvas * c)
{
	start = p0;
	end = p1;
	color = Color(0,0,0);
	hidden = false;
	canvas = c;
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
void FilledRect::render()
{
	if(hidden) return;
	
	sceGuDisable(GU_TEXTURE_2D);
	sceGuDisable(GU_DEPTH_TEST);
	
	Vertex * points = (Vertex *)sceGuGetMemory(sizeof(Vertex) * 4);
	points[0].color = points[1].color = points[2].color = points[3].color = color.gu_c();
	points[0].z = points[1].z = points[2].z = points[3].z = 0.0f;
	
	points[0].x = points[2].x = getX();
	points[1].x = points[3].x = getX() + getWidth();
	
	points[0].y = points[1].y = getY();
	points[2].y = points[3].y = getY() + getHeight();
	
	sceGuDrawArray(GU_TRIANGLE_STRIP, GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 4, 0, points);
	
	sceGuEnable(GU_TEXTURE_2D);
	sceGuEnable(GU_DEPTH_TEST);
}
string FilledRect::toString()
{
	stringstream rstr("FilledRect: ");
	rstr << "start: " << start.toString() << 
	"end: " << end.toString() << 
	"color: " << color.toString() <<
	"hidden: " << hidden;
	return rstr.str();
}
